﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Mvc.XForms.Examples.Model;

namespace Mvc.XForms.Examples.Repository {
	public class InMemoryRepository<TEntity> : IRepository<TEntity> where TEntity : IEntity {
		private InMemoryDataContext testDB;

		public InMemoryRepository(InMemoryDataContext testDB) {
			this.testDB = testDB;
		}

		public IQueryable<TEntity> AsQueryable() {
			return testDB.AsQueryable<TEntity>();
		}

		public TEntity Get(long entityID) {
			return testDB.Get<TEntity>(entityID);
		}

		public void Add(TEntity entity) {
			testDB.AddEntity(entity);
		}

		public void Update(TEntity entity) {
			// Do nothing. We actually need to implement cloning
		}

		public void Delete(TEntity entity) {
			testDB.Remove(entity);
		}
	}
}